﻿#include "FITKAcousticsVTKGraphObjectSEAJunctionAreas.h"
#include "FITKAcousticsVTKGraphActor.h"

// VTK
#include <vtkProperty.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkCompositeDataGeometryFilter.h>
#include <vtkExtractBlock.h>

// Data
#include "FITK_Component/FITKAcousticsModel/FITKSEAAbstractJunction.h"

// Graph and filter
#include "FITKAcousticsVTKCommons.h"
#include "FITKAcousticsVTKSharedDataManager.h"
#include "FITKAcousticsVTKGraphObjectSEASelectMergedData.h"
#include "FITK_Interface/FITKVTKAlgorithm/FITKGraphActor.h"

namespace Exchange
{
    FITKAcousticsVTKGraphObjectSEAJunctionAreas::FITKAcousticsVTKGraphObjectSEAJunctionAreas(Acoustics::FITKAcousticsDiscModel* seaModel)
        : FITKAcousticsVTKGraphObjectSEAJunctions(seaModel)
    {
        if (!seaModel)
        {
            return;
        }

        // Intiailize the polygon offset.
        m_polygonOffset = FITKAcousticsVTKCommons::s_polygonOffsetSEAJunction;

        // Initialize the SEA junctions type.
        m_SEAJunctionTypeEnum = Acoustics::FITKAbstractJunction::JunctionType::SEAAreaJunction;

        // Intialize the filter.
        init();

        // Generate the multi block dataset.
        if (!generateDataSet())
        {
            return;
        }

        // Generate the actor.
        generateGraph();

        // Update the visibility.
        updateVisibility();

        // Save the data type.
        m_graphInfo.Type = FITKAcousticsVTKCommons::JunctionArea;
    }

    bool FITKAcousticsVTKGraphObjectSEAJunctionAreas::getDataVisibility()
    {
        // Get the runtime settings for visibility.
        bool showSEAJunc = this->Superclass::getDataVisibility();
        bool showJArea = getRuntimeSettingAs<bool>(RTS_KEY_VISIBLE_JUNCTION_AREAS, true);
        bool showSEAJArea = getRuntimeSettingAs<bool>(RTS_KEY_VISIBLE_SEA_JUNC_AREAS, true);
        return showSEAJunc && showJArea && showSEAJArea;
    }

    bool FITKAcousticsVTKGraphObjectSEAJunctionAreas::generateDataSet()
    {
        // Initialize the input of filter.
        //vtkMultiBlockDataSet* mDataSet = FITKAcousticsVTKSharedDataManager::GetInstance()->
        //    getSEAJunctionsMultiDataSet(Acoustics::FITKSEAAbstractJunction::SEAJunctionType::Area);
        //if (!mDataSet)
        //{
        //    return false;
        //}

        //m_extractBlock->SetInputData(mDataSet);
        return true;
    }

    void FITKAcousticsVTKGraphObjectSEAJunctionAreas::generateGraph()
    {
        // Create grid actor.
        this->Superclass::generateGraph();

        m_fActor->setActorType(ActorType::SurfaceActor);

        // Enable the color array.
        m_fActor->setScalarVisibility(true);
        m_fActor->setScalarModeToUseCellFieldData();
        m_fActor->selectScalarArray(DATA_COLOR_ARRAY_NAME);
    }
}   // namespace Exchange